//
//  WWContentTableCell.m
//  YiQiTingShu
//
//  Created by WeiWei on 15/11/5.
//  Copyright © 2015年 直到世界的尽头. All rights reserved.
//

#import "WWContentTableCell.h"
#import <UIImageView+WebCache.h>
#import "PublicHeader.h"

@interface WWContentTableCell ()

@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UILabel *introLabel;
@property (nonatomic, strong) UILabel *trackLabel;
@property (nonatomic, strong) UILabel *countLabel;
@property (nonatomic, strong) UIImageView *coverImageView;
@property (nonatomic, strong) UIImageView *trackImageView;
@property (nonatomic, strong) UIImageView *countImageView;

@end

@implementation WWContentTableCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        _titleLabel = [[UILabel alloc] init];
        [self.contentView addSubview:_titleLabel];
        _introLabel = [[UILabel alloc] init];
        [self.contentView addSubview:_introLabel];
        _trackLabel = [[UILabel alloc] init];
        [self.contentView addSubview:_trackLabel];
        _countLabel = [[UILabel alloc] init];
        [self.contentView addSubview:_countLabel];
        _coverImageView = [[UIImageView alloc] init];
        [self.contentView addSubview:_coverImageView];
        _trackImageView = [[UIImageView alloc] init];
        [self.contentView addSubview:_trackImageView];
        _countImageView = [[UIImageView alloc] init];
        [self.contentView addSubview:_countImageView];
        [self.titleLabel NightWithType:UIViewColorTypeNormal];
        [self.introLabel NightWithType:UIViewColorTypeNormal];
        [self.trackLabel NightWithType:UIViewColorTypeNormal];
        [self.countLabel NightWithType:UIViewColorTypeNormal];
        [self.contentView NightWithType:UIViewColorTypeNormal];
    }
    return self;
}

- (void)setModel:(WWTableContentModel *)model {
    if (_model != model) {
        _model = model;
    }
    [self.coverImageView sd_setImageWithURL:[NSURL URLWithString:model.coverMiddle] placeholderImage:[UIImage imageNamed:@"placeholderZh.png"]];
    self.titleLabel.text = model.title;
    self.introLabel.text = model.intro;
    NSString *count = [NSString stringWithFormat:@"%@", model.playsCounts];
    if (count.length > 5) {
        NSMutableString *string = [count substringToIndex:(count.length - 3)].mutableCopy;
        [string insertString:@"." atIndex:(string.length - 1)];
        self.trackLabel.text = [NSString stringWithFormat:@"%@万", string];
    } else if (count.length < 5) {
        self.trackLabel.text = [NSString stringWithFormat:@"%@", count];
    } else if (count.length == 5){
        NSMutableString *string = [count substringToIndex:(count.length - 4)].mutableCopy;
        self.trackLabel.text = [NSString stringWithFormat:@"%@万", string];
    } else {
        self.trackImageView.hidden = YES;
        self.trackLabel.hidden = YES;
    }
    self.countLabel.text = [NSString stringWithFormat:@"%@集", model.tracks];
    self.trackImageView.image = [UIImage imageNamed:@"sanjiao1.png"];
   
}

-(void)setSearchModel:(FSearchAlbumModel *)searchModel
{
    if (_searchModel != searchModel) {
        _searchModel = searchModel;
    }
    [self.coverImageView sd_setImageWithURL:[NSURL URLWithString:searchModel.cover_path] placeholderImage:[UIImage imageNamed:@"placeholderZh.png"]];
    self.titleLabel.text = searchModel.title;
    self.introLabel.text = searchModel.intro;
    NSString *count = [NSString stringWithFormat:@"%@", searchModel.play];
    if (count.length > 5) {
        NSMutableString *string = [count substringToIndex:(count.length - 3)].mutableCopy;
        [string insertString:@"." atIndex:(string.length - 1)];
        self.trackLabel.text = [NSString stringWithFormat:@"%@万", string];
    } else if (count.length < 5) {
        self.trackLabel.text = [NSString stringWithFormat:@"%@", count];
    } else if (count.length == 5){
        NSMutableString *string = [count substringToIndex:(count.length - 4)].mutableCopy;
        self.trackLabel.text = [NSString stringWithFormat:@"%@万", string];
    } else {
        self.trackImageView.hidden = YES;
        self.trackLabel.hidden = YES;
    }
    self.countLabel.text = [NSString stringWithFormat:@"%@集", searchModel.tracks];
    self.trackImageView.image = [UIImage imageNamed:@"sanjiao1.png"];
}

- (void)layoutSubviews {
    [super layoutSubviews];
    self.coverImageView.frame = CGRectMake(FitConstant_XorWidth(5), FitConstant_YorHeight(4), FitConstant_XorWidth(73), FitConstant_YorHeight(72));
    self.titleLabel.frame = CGRectMake(FitConstant_XorWidth(78), FitConstant_YorHeight(4), FitConstant_XorWidth(300), FitConstant_YorHeight(18));
    self.introLabel.frame = CGRectMake(FitConstant_XorWidth(78), FitConstant_YorHeight(30), FitConstant_XorWidth(234), FitConstant_YorHeight(18));
    self.introLabel.textColor = [UIColor lightGrayColor];
    self.introLabel.font = [UIFont systemFontOfSize:15];
    self.trackImageView.frame = CGRectMake(FitConstant_XorWidth(78), FitConstant_YorHeight(56), FitConstant_XorWidth(13), FitConstant_YorHeight(15));
    self.trackLabel.frame = CGRectMake(FitConstant_XorWidth(90), FitConstant_YorHeight(55), FitConstant_XorWidth(100), FitConstant_YorHeight(18));
    self.trackLabel.textColor = [UIColor lightGrayColor];
    self.trackLabel.font = [UIFont systemFontOfSize:15];
    self.countLabel.frame = CGRectMake(FitConstant_XorWidth(190), FitConstant_YorHeight(55), FitConstant_XorWidth(123), FitConstant_YorHeight(18));
    self.countLabel.textColor = [UIColor lightGrayColor];
    self.countLabel.font = [UIFont systemFontOfSize:15];
}

@end
